package command;

/**
 * 
 * @author rensbonnez
 *
 */

public class Command 
{
	private CommandType commandType;
	private String message;
	
	/**
	 * Constructor
	 * @param command
	 */
	public Command(String command)
	{
		String[] splitForFiles = command.split("<FILES>");
		
		if(splitForFiles.length > 1)
		{
			setMessage(splitForFiles[1]);
		}
		
		setCommandType(stringToCommandType(splitForFiles[0]));
	}
	
	/**
	 * Constructor
	 * @param commandType
	 */
	public Command(CommandType commandType)
	{
		setCommandType(commandType);
	}
	
	/**
	 * Method will return the string of commandType
	 * @return String
	 */
	public String toString()
	{
		return commandToString(commandType);
	}
	
	/**
	 * Method to get the string of a commanType
	 * @param commandType
	 * @return String
	 */
	private String commandToString(CommandType commandType)
	{
		switch(commandType)
		{
			case HELLO : return "HELLO";
			case WELCOME : return "WELCOME";
			case GETLIST : return "GETLIST";
			case SENDLIST : return "SENDLIST";
			case GOODBYE : return "GOODBYE";
			default : return "UNKNOWN";
		}
	}
	
	/**
	 * Method to get the CommandType of a String
	 * @param command
	 * @return CommandType
	 */
	private CommandType stringToCommandType(String command)
	{
		String commandType = command.split("::")[0];
		
		if(commandType.equalsIgnoreCase("HELLO"))
			return CommandType.HELLO;
		else if(commandType.equalsIgnoreCase("WELCOME"))
			return CommandType.WELCOME;
		else if(commandType.equalsIgnoreCase("GETLIST"))
			return CommandType.GETLIST;
		else if(commandType.equalsIgnoreCase("SENDLIST"))
			return CommandType.SENDLIST;
		else if(commandType.equalsIgnoreCase("GOODBYE"))
			return CommandType.GOODBYE;
		return null;
	}
	
	/**
	 * 
	 * Getters & Setters 
	 * 
	 */
	
	public CommandType getCommandType() {
		return commandType;
	}

	public void setCommandType(CommandType commandType) {
		this.commandType = commandType;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}
}
